home *** CD-ROM | disk | FTP | other *** search
/ Future Workshop / Future Workshop.iso / utility / formula1 / vcform1.3 / VB4 / ODBC2 / ODBC2.TXT < prev    next >
Encoding:
Text File  |  1995-09-15  |  5.4 KB  |  168 lines

  1. Attribute VB_Name = "Module1"
  2. Option Explicit
  3.  
  4. '' The following constants are defined in ODBCINST.H in MSVC++ 2.2
  5. Global Const ODBC_ADD_DSN = 1         ' Add data source
  6. Global Const ODBC_CONFIG_DSN = 2      ' Configure (edit) data source
  7. Global Const ODBC_REMOVE_DSN = 3      ' Remove data source
  8.  
  9. '' This function is part of ODBCCP32.DLL and is used to setup a data source.
  10. '' If the first arg is NULL, no dialog will be shown when the function
  11. '' is called. The second arg may be one of ODBC_ADD_DSN, ODBC_CONFIG_DSN,
  12. '' or ODBC_REMOVE_DSN. The third arg is the Driver description used instead
  13. '' of the physical driver name. The last arg is a set of keyword value
  14. '' pairs that setup the data source. See the ODBC API help file ODBC20.HLP
  15. '' distributed with MSVC++ 2.0 for more info.
  16.  
  17. Declare Function SQLConfigDataSource Lib "odbccp32.dll" (ByVal hWndParent&, ByVal fRequest%, ByVal lpszDriver$, ByVal lpszAttributes$) As Boolean
  18.  
  19. Sub MakeYellowGreenBars(SS As Object, whichSheet&)
  20. '' Formats rows as alternating yellow and green bars from 1 to LastRow
  21. '' On the given sheet. If you make this for only the cells with data
  22. '' you will be adding a format for each cell which will use much
  23. '' more RAM (flag + 2 colors + pattern) * num cells
  24.  
  25.    Dim r&, c&
  26.  
  27.    c = -1
  28.    With SS
  29.       .Sheet = whichSheet
  30.       .SetSelection 1, c, 1, c
  31.       For r = 3 To .LastRow Step 2
  32.          .AddSelection r, c, r, c
  33.       Next r
  34.       .SetPattern 4, .PaletteEntry(4), .PaletteEntry(2)
  35.       
  36.       .SetSelection 2, c, 2, c
  37.       For r = 4 To .LastRow Step 2
  38.          .AddSelection r, c, r, c
  39.       Next r
  40.       .SetPattern 4, .PaletteEntry(6), .PaletteEntry(2)
  41.       .Selection = "A1"
  42.    End With
  43.       
  44. End Sub
  45.  
  46. Sub SetRowColCalc(SS As Object, wsFunc$, startRow&, endRow&, startCol&, endCol&)
  47. '' Assumes a rectangle of data and sets formulas in the col to
  48. '' the right of the data that is the given function over the given
  49. '' range. Inserts formulas from row 1 to LastRow.
  50.  
  51.    Dim formula$, savedSelection$
  52.    
  53.    With SS
  54.       Let savedSelection = .Selection
  55.  
  56.       '' Column formula
  57.       Let formula = wsFunc & "(" & .FormatRCNr(startRow, startCol, False) _
  58.          & ":" & .FormatRCNr(startRow, endCol, False) & ")"
  59.       .SetSelection startRow, endCol + 1, startRow, endCol + 1
  60.       .formula = formula
  61.       .SetSelection startRow, endCol + 1, endRow, endCol + 1
  62.       .EditCopyDown
  63.  
  64.       '' Row formula
  65.       Let formula = wsFunc & "(" & .FormatRCNr(startRow, startCol, False) _
  66.          & ":" & .FormatRCNr(endRow, startCol, False) & ")"
  67.       .SetSelection endRow + 1, startCol, endRow + 1, startCol
  68.       .formula = formula
  69.       .SetSelection endRow + 1, startCol, endRow + 1, endCol + 1
  70.       .EditCopyRight
  71.          
  72.       .Selection = savedSelection
  73.    End With
  74.    
  75. End Sub
  76.  
  77. Sub FormatSalesCrossTab(SS As Object, whichSheet&)
  78. '' Formats rows as yellow and green bars with the right column
  79. '' and bottom row grey with a single border on the inside.
  80.  
  81.    Dim savedSelection$
  82.  
  83.    With SS
  84.       Let savedSelection = .Selection
  85.       Call MakeYellowGreenBars(SS, whichSheet)
  86.       
  87.       '' Format column
  88.       .SetSelection -1, .LastCol, -1, .LastCol
  89.       .SetPattern 4, .PaletteEntry(15), .PaletteEntry(2)
  90.       .SetBorder -1, 1, 5, -1, -1, 0, 0, 0, 0, 0, 0
  91.  
  92.       '' Format row
  93.       .SetSelection .LastRow, -1, .LastRow, -1
  94.       .SetPattern 4, .PaletteEntry(15), .PaletteEntry(2)
  95.       .SetBorder -1, -1, -1, 1, 5, 0, 0, 0, 0, 0, 0
  96.  
  97.       '' Now set an outline and max RC
  98.       .MaxRow = .LastRow
  99.       .MaxCol = .LastCol
  100.  
  101.       '' Now resize all cells so they can display their data
  102.       .SetColWidthAuto -1, -1, -1, -1, True
  103.       
  104.       .Selection = savedSelection
  105.    End With
  106.    
  107. End Sub
  108. Sub Fetch(SS As Object, whichSheet&, startRow&, startCol&, dsName$, query$, _
  109.    setColNames As Boolean, setColFormats As Boolean, setColWidths As Boolean, _
  110.    setMaxRC As Boolean)
  111.    '' Performs the query and places on wheet with given options
  112.    
  113.    On Error GoTo FetchError
  114.    Dim returnCode%
  115.  
  116.    With SS
  117.       .Sheet = whichSheet
  118.       .ODBCConnect dsName, True, returnCode
  119.       .ODBCQuery query, startRow, startCol, False, setColNames, _
  120.          setColFormats, setColWidths, setMaxRC, returnCode
  121.       .ODBCDisconnect
  122.    End With
  123.    
  124.    Exit Sub
  125. FetchError:
  126.    MsgBox Error
  127. End Sub
  128.  
  129. Sub NameAndFormatColumn(SS As Object, whichSheet&, col&, what$, numFormat$)
  130. '' Sets the Column text of the specified sheet to to what and
  131. '' then sets the col width to accommodate.
  132.  
  133.    Dim savedSheet&, savedSelection$
  134.    
  135.    With SS
  136.       savedSheet = .Sheet
  137.       savedSelection = .Selection
  138.       .Sheet = whichSheet
  139.       .ColText(col) = what
  140.       .SetColWidthAuto -1, col, -1, col, True
  141.       .SetSelection -1, col, -1, col
  142.       .NumberFormat = numFormat
  143.       .Sheet = savedSheet
  144.       .Selection = savedSelection
  145.    End With
  146.    
  147. End Sub
  148.  
  149. Sub NameAndFormatRow(SS As Object, whichSheet&, row&, what$, numFormat$)
  150. '' Sets the Row text of the specified sheet to to what and
  151. '' then sets the row header width to accommodate.
  152.  
  153.    Dim savedSheet&, savedSelection$
  154.  
  155.    With SS
  156.       savedSheet = .Sheet
  157.       savedSelection = .Selection
  158.       .Sheet = whichSheet
  159.       .RowText(row) = what
  160.       .SetSelection row, -1, row, -1
  161.       .NumberFormat = numFormat
  162.       .Sheet = savedSheet
  163.       .Selection = savedSelection
  164.    End With
  165.  
  166.    
  167. End Sub
  168.